{% macro chapter_tree(chapters) %}
    {% if chapters is not empty %}
    <ol class="dd-list">
        {% for chapter in chapters %}
            <li class="dd-item" data-id="{{ chapter['id'] }}">
                <div class="dd-handle">
                    {{ loop.index }}. &nbsp;<strong>{{ chapter['name']|raw }}</strong>
                    
                    <span class="pull-right dd-nodrag">
                {% if is_authorized('admin_cms_tutorial_chapter_add') and (chapter['parentId'] == 0) %}
                    <a href="{{ path("admin_cms_tutorial_chapter_add", {"id":chapter['tutorialId']}) }}?pid={{ chapter['id'] }}" data-title="添加子章节"  title="添加子章节" class="poppage"><i class="mdi mdi-plus"></i></a>
                {% endif %}

                {% if is_authorized('admin_cms_tutorial_chapter_edit') %}
                    <a href="{{ path("admin_cms_tutorial_chapter_edit", {"id":chapter['id']}) }}" data-title="编辑"  title="编辑" class="poppage"><i class="mdi mdi-file-document-edit"></i></a>
                {% endif %}

                {% if is_authorized('admin_cms_tutorial_chapter_edit_content') %}
                    <a href="{{ path("admin_cms_tutorial_chapter_edit_content", {"id":chapter['id']}) }}" data-title="编辑内容"  title="编辑内容" class="poppage"><i class=" mdi mdi-circle-edit-outline"></i></a>
                {% endif %}

                {% if is_authorized('admin_api_cms_tutorial_chapter_delete') %}
                    <a href="{{ path("admin_api_cms_tutorial_chapter_delete", {"id":chapter['id']}) }}" title="删除"  data-confirm="确认要删除吗?" class="tree_branch_delete ajaxDelete"><i class="mdi mdi-delete"></i></a>
                {% endif %}
                </span>
                </div>
                {{ _self.chapter_tree(chapter['childs']) }}
            </li>
        {% endfor %}
    </ol>
    {% endif %}
{% endmacro %}
